package com.taotao.content.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.taotao.common.dto.PageResult;
import com.taotao.content.service.ContentService;
import com.taotao.dao.ContentDao;
import com.taotao.entity.Content;
import com.taotao.entity.ContentExample;
import com.taotao.entity.ContentExample.Criteria;

/**  
 * @Title：ContentServiceImpl.java   
 * @Description：
 * @Author：张朝阳
 * @Date：2019年7月8日 下午10:31:55   
 */

@Service
public class ContentServiceImpl implements ContentService {

	@Autowired
	private ContentDao contentDao;
	
	@Override
	public void addContent(Content content) {
		content.setCreated(new Date());
		content.setUpdated(new Date());
		contentDao.insert(content);
	}

	@Override
	public List<Content> getListByCategoryIdForPage(int pageNum, int pageSize, Long categoryId) {
		ContentExample example = new ContentExample();
		Criteria criteria = example.createCriteria();
		criteria.andCategoryIdEqualTo(categoryId);
		PageHelper.startPage(pageNum, pageSize);
		List<Content> contentList = contentDao.selectByExample(example);
		return contentList;
	}

	@Override
	public List<Content> getListByCategoryId(Long categoryId) {
		ContentExample example = new ContentExample();
		Criteria criteria = example.createCriteria();
		criteria.andCategoryIdEqualTo(categoryId);
		List<Content> contentList = contentDao.selectByExample(example);
		return contentList;
	}

}
